package com.zw.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zw.pojo.TOrderInfo;
import com.zw.service.TOrderInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 订单管理表;主要保存总订单信息，下单时间、支付状态、下单金额等(TOrderInfo)表控制层
 *
 * @author makejava
 * @since 2024-11-23 23:47:01
 */
@RestController
@RequestMapping("tOrderInfo")
public class TOrderInfoController {
    /**
     * 服务对象
     */
    @Resource
    private TOrderInfoService tOrderInfoService;

    @GetMapping("/firstTest")
    @HystrixCommand(fallbackMethod = "firstTestFallbackMethod")
    public List<TOrderInfo> firstTest() throws InterruptedException {
        long startTime = System.currentTimeMillis();
        TimeUnit.SECONDS.sleep(6);
        List<TOrderInfo> delFlag = tOrderInfoService.list(new QueryWrapper<TOrderInfo>().eq("del_flag", 0));
        System.out.println(System.currentTimeMillis()-startTime);
        return delFlag;
    }

    public List<TOrderInfo> firstTestFallbackMethod() {
        List<TOrderInfo> list = new ArrayList<>();
        TOrderInfo tOrderInfo = new TOrderInfo();
        tOrderInfo.setOrderCode("这个是HystrixCommand 《熔断》提供的避免级联故障或者是雪崩的备选方案");
        list.add(tOrderInfo);
        return list;
    }
}

